<template>
  <div v-if="isLogin">
    <div class="member">
      <div class="header-con">
        <div class="user-info">
          <!-- 用户信息 -->
          <div class="avatar-con">
            <van-icon
              name="https://b.yzcdn.cn/vant/icon-demo-1126.png"
              size="60"
            />
          </div>
          <div class="person-con">
            <span>{{ userName }}</span>
          </div>
        </div>
      </div>
    </div>
    <van-cell-group inset class="fun-list">
      <van-cell
        :to="{ name: 'order_list' }"
        title="我的订单"
        icon="balance-list-o"
        is-link
      />
      <van-cell
        :to="{ name: 'address' }"
        title="收货地址"
        icon="location-o"
        is-link
      />
      <van-cell
        url="https://gitee.com/code-jay/micro_shop"
        title="码云仓库"
        icon="exchange"
        is-link
      />
      <van-cell @click="clickLogout()" title="退出登录" icon="close" is-link />
    </van-cell-group>
  </div>
  <div v-else>
    <div class="member">
      <div class="header-con">
        <router-link :to="{ name: 'login' }" class="mui-navigate-right">
          <div class="user-info">
            <!-- 用户信息 -->
            <div class="avatar-con">
              <van-icon
                name="https://b.yzcdn.cn/vant/icon-demo-1126.png"
                size="60"
              />
            </div>
            <div class="person-con">
              <span>登录 / 注册</span>
            </div>
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters, mapMutations } from "vuex";
export default {
  computed: {
    ...mapGetters("user", ["userName"]),
    ...mapGetters("user", { isLogin: "isLogin" }),
    ...mapMutations("user", ["login"]),
  },
  methods: {
    clickLogout() {
      this.$store.commit("shopcart/clearCart_F");
      this.$store.commit("address/clearAddress");
      this.$store.commit("user/logout");
      this.$store.commit("order/clearOrder");
      this.$toast.success("退出成功");
    },
  },
};
</script>

<style lang="scss" scoped>
.member {
  margin-bottom: 15px;
  .header-con {
    padding: 16px;
    background-color: #fff;
    .user-info {
      border-radius: 10px;
      position: relative;
      overflow: hidden;
      width: 100%;
      height: 120px;
      box-shadow: 0 0.1rem 0.25rem #ccc;
      .avatar-con {
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        .avatar {
          .image-info {
            width: 100%;
            height: 100%;
          }
        }
      }
      .person-con {
        position: absolute;
        left: 90px;
        top: 50%;
        transform: translateY(-50%);
        color: #1989fa;
      }
    }
  }
}
.fun-list {
  box-shadow: 0 0.1rem 0.25rem #ccc;
}
</style>
